exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  indexAction() {}
  /**
     * 获取所有字典表信息
     */
  initdictionaryAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const DictionaryService = _this.service('sys/DictionaryService');
      const res = yield DictionaryService.buildDictData();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '获取数据字典失败';
      }
      return _this.json(aj);
    })();
  }

  /**
     * 同步字典,缓存至redis
     * @param req
     * @param res
     */
  initdictcacheAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const DictionaryService = _this2.service('sys/DictionaryService');
      const res = yield DictionaryService.initDictionaryCache();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '获取数据字典失败';
      }
      return _this2.json(aj);
    })();
  }

  /**
     * 查询字典list(带分页)
     */
  finddictionarylistAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = _this3.get('page,pageSize,typegroupname');
      const DictionaryService = _this3.service('sys/DictionaryService');
      const res = yield DictionaryService.findDictionaryList(data);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '字典信息获取失败';
      }
      return _this3.json(aj);
    })();
  }

  /**
     * 新增或更新字典
     */
  addorupdatedictionaryAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = _this4.post('typegroupcode,typegroupname');
      if (_this4.post('id')) {
        data.id = _this4.post('id');
      }
      const DictionaryService = _this4.service('sys/DictionaryService');
      const res = yield DictionaryService.saveDicInfo(data);
      if (res.error) {
        aj.success = false;
        aj.msg = '字典信息保存错误';
      }
      if (!res) {
        aj.success = false;
        aj.msg = '字典编码不能重复，请重新输入';
      }
      return _this4.json(aj);
    })();
  }
  /**
     * 单条删除和批量删除
     */
  deletedicAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = { id: _this5.post('id') };
      const DictionaryService = _this5.service('sys/DictionaryService');
      const res = yield DictionaryService.delDicInfo(data);
      if (res.error) {
        aj.success = false;
        aj.msg = '字典信息删除错误';
      }
      return _this5.json(aj);
    })();
  }

  /**
     * 根据groupId查询字典类型
     */
  finddictypelistAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const groupId = _this6.get('groupId');
      const DictionaryService = _this6.service('sys/DictionaryService');
      const res = yield DictionaryService.findDicTypeList(groupId);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '字典类型获取失败';
      }
      return _this6.json(aj);
    })();
  }

  /**
     * 新增或更新字典类型
     */
  addorupdatedictypeAction() {
    var _this7 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = _this7.post('typecode,typename,typegroupid,other_attr');
      if (_this7.post('id')) {
        data.id = _this7.post('id');
      }
      const DictionaryService = _this7.service('sys/DictionaryService');
      const res = yield DictionaryService.saveDicTypeInfo(data);
      if (res.error) {
        aj.success = false;
        aj.msg = '字典类型信息保存错误';
      }
      return _this7.json(aj);
    })();
  }

  deletedictypeAction() {
    var _this8 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = { id: _this8.post('id') };
      const DictionaryService = _this8.service('sys/DictionaryService');
      const res = yield DictionaryService.delDicTypeInfo(data);
      if (res.error) {
        aj.success = false;
        aj.msg = '字典类型信息删除错误';
      }
      return _this8.json(aj);
    })();
  }
};